<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>微信机构</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
    <style>
        .wechat_cross_btn_group {
            margin-left: 15px;
        }
    </style>
</head>

<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">{:lang('user_child')}</div>
                <div class="layui-btn-group wechat_cross_btn_group">
                    <button class="layui-btn layui-btn-sm" lay-href="{:url('user/add')}" lay-text="{:lang('user_add')}">
                        <i class="layui-icon">&#xe654;</i>{:lang('add_user')}
                    </button>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="mechanism_list" lay-filter="user_list"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--({{ d.u_child_count }})-->
<script type="text/html" id="do">
    <a class="layui-btn layui-btn-xs" lay-event="edit">{:lang('edi_user')}</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">{:lang('delete_user')}</a>
</script>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery'], function () {
        var table = layui.table;
        var $ = layui.jquery;

        table.render({
            elem: '#mechanism_list'
            , url: "{:url('api/user/getList')}"
            , where: { //设定异步数据接口的额外参数，任意设
                u_id : "{$u_id}",
                // u_account : '10001780' // 指定搜索登录账号
            }
            , cols: [[
                {field: 'u_id', title: '用户id', fixed: 'left', width: 100}
                , {field: 'u_name', title: '用户名'}
                , {field: 'role_name', title: '角色'}
                , {field: 'u_account', title: '登录账号'}
                , {field: 'create_time', title: '添加时间'}
                , {toolbar: '#do', width: 300}
            ]]
            , page: true

            , response: {
                countName: 'msg' //规定数据总数的字段名称，默认：count
                , dataName: 'data' //规定数据列表的字段名称，默认：data
            }
        });


        // 监听工具条
        table.on('tool(user_list)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event; //获得 lay-event 对应的值
            var ticketcode = data.ticketcode;

            switch (layEvent) {
                case 'merchantView':
                    var url = "{:url('merchant/entrance', ['u_id' => '__UID__', 'u_name' => '__NAME__'])}";
                    url =  url.replace("__UID__", data.u_id);
                    url =  url.replace("__NAME__", data.u_name);
                    var text = data.u_name + '商户';
                    //执行跳转
                    var topLayui = parent === self ? layui : top.layui;
                    topLayui.index.openTabsPage(url, text);
                    break;

                // 下级用户列表
                case 'userChild':
                    var url = "{:url('user/childList', ['u_id' => '__UID__'])}";
                    url =  url.replace("__UID__", data.u_id);

                    var text = data.u_name + '用户';
                    //执行跳转
                    var topLayui = parent === self ? layui : top.layui;
                    topLayui.index.openTabsPage(url, text);
                    break;

                case 'del':
                    layer.confirm('确认删除该用户?', {icon: 3, title: '提示'}, function (index) {
                        $.ajax({
                            url: "{:url('api/user/del')}",
                            data: {
                                u_id: data.u_id
                            },
                            type: "post",
                            dataType: "json",
                            success: function (res) {
                                if (res.code === '200') {
                                    window.location.reload();
                                } else {
                                    layer.msg(res.msg, {
                                        icon: 2
                                    })
                                }
                            }
                        });

                        layer.close(index);
                    });
                    break;
                case 'edit':
                    var url = "{:url('user/edit', ['u_id' => '__UID__', 'u_name' => '__NAME__'])}";
                    url =  url.replace("__UID__", data.u_id);
                    url =  url.replace("__NAME__", data.u_name);
                    var text = data.u_name + '商户';
                    //执行跳转
                    var topLayui = parent === self ? layui : top.layui;
                    topLayui.index.openTabsPage(url, text);
                    break;
                default:
                    // layer.msg('未知操作');
                    break;
            }
        });
        // 监听工具条结束
    });
</script>
</body>

</html>